#!/usr/bin/env groovy

def call(String techStack = '') {
   echo "========================PUSH IMAGE================================="

   if (techStack == 'springboot') {
      sh label: 'DOCKER-BATCH-PUSH', returnStdout: true, script: 
      '''
      docker login --username=${HARBOR_ACCESS_KEY_USR} --password=${HARBOR_ACCESS_KEY_PSW} ${HARBOR}

      for i in $(docker images | grep -v none| grep ^${HARBOR}/${PROJECT_NAME}/|grep ${VERSION_NUMBER} | awk 'BEGIN{OFS=":"}{print $1,$2}'); do docker push $i; done
      '''

   } else {
      sh label: 'DOCKER-PUSH', returnStdout: true, script: '''   
      echo "push image: ${HARBOR}/${PROJECT_NAME}/${DOCKER_NAME}:${VERSION_NUMBER}"    
      docker login --username=${HARBOR_ACCESS_KEY_USR} --password=${HARBOR_ACCESS_KEY_PSW} ${HARBOR}
      docker push ${HARBOR}/${PROJECT_NAME}/${DOCKER_NAME}:${VERSION_NUMBER}
      '''
   }

   echo "===============================DONE=================================" 
}

